package com.scs.application.modules.sys.vo;

import com.scs.application.core.utils.StringUtils;
import lombok.Data;

@Data
public class TableColumn {
    private String name;
    private String title;
    private String dataType;
    private String isNullable;
    private double characterMaximumLength;
    private double numericPrecision;
    private double numericScale;
    private String columnKey;
    private String extra;
    private double sort;
    private String columnDefault;
    // 扩展字段
    private Boolean isAutoIncrease;
    private String propertyName;
    private String text;
    private String commet;
    private String propertyType;
    private Boolean propertyNotNull;

    public void setExtendInfo() {
        this.isAutoIncrease = extra.contains("auto_increment");
        this.propertyName = StringUtils.camelCase(this.name);
        this.text = this.title.split("\\|")[0];
        this.commet = this.title.split("\\|").length > 1 ?  this.title.split("\\|")[1]:"";
        this.propertyType = getPropertyType(this.dataType);
        this.propertyNotNull = !this.isNullable.equalsIgnoreCase("YES");
    }
    private String getPropertyType(String fieldType) {
        switch (fieldType) {
            case "varchar":
            case "text":
            case "char":
                return "String";
            case "bigint":
                return "Long";
            case "int":
            case "smallint":
                return "Integer";
            case "tinyint":
                return "Boolean";
            case "decimal":
            case "double":
            case "float":
                return "Double";
            case "datetime":
            case "date":
                return "Date";
            default:
                return "Unknown";
        }
    }
}
